package day02;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/*
 * 1.存储全班的同学的姓名 就存储三个
 * 2.总览全部的同学姓名
 * 3.随机点名其中一人 打印到控制台
 */

public class homework {
	public static void main(String[] args) {
		ArrayList<Student> student =new ArrayList<Student>() ;
		//添加学生
		addStudent(student);
		//打印学生
		printStudnetName(student);
		//获取随机点名到的学生的姓名
		int rand=randomStdudentName(student);
		Student stu=student.get(rand);
		System.out.println("被随机抽到的是第"+rand+"个学生,"+"他的信息:"+stu.toString());
	}
	private static void addStudent(ArrayList<Student> student ) {
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入要添加的学生信息");
		for(int i=0;i<3;i++){
			System.out.println("存储第"+i+"个名称:");
			String name=sc.next();
			int age=sc.nextInt();
			Student sdt=new Student(i+1,name,age);
			student.add(sdt);
		}
	}
	private static void printStudnetName(ArrayList<Student> student) {
		for (int i = 0; i < student.size(); i++) {
			Student stud=student.get(i);
			System.out.println("第"+i+"个学生的信息:"+stud);
		}
	}
	private static int randomStdudentName(ArrayList<Student> student) {
		Random random = new Random();
		int index = random.nextInt(student.size());
		return index;
	}
}